var _o28;
var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2BundleManager = require("BundleManager");
var $2GameConfig = require("GameConfig");
var $2GameUser = require("GameUser");
var $2levelconfig = require("levelconfig");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_Globe = _o28 = /* */function (_cc$Component16) {
  function _ctor() {
    var _this42;
    babel_classCallCheck(this, _ctor);
    _this42 = _callSuper(this, _ctor, arguments);
    _this42.is_UIPsetting = false;
    _this42.currlv_range = 0;
    _this42._intersecRect = new cc.Rect();
    return _this42;
  }
  babel_inherits(_ctor, _cc$Component16);
  return babel_createClass(_ctor, [{
    key: "random",
    value: function random(e, t) {
      return Math.floor(Math.random() * (t - e + 1)) + e;
    }
  }, {
    key: "setAnimationByControl",
    value: function setAnimationByControl(e, t, n, _o29) {
      return e.setAnimation(t, n, _o29);
    }
  }, {
    key: "addAnimationByControl",
    value: function addAnimationByControl(e, t, n, _o30) {
      return e.addAnimation(t, n, _o30);
    }
  }, {
    key: "setTrackEventListenerByControl",
    value: function setTrackEventListenerByControl(e, t, n, _o31) {
      e.setTrackEventListener(t, function (e, t) {
        t.data.name == n && _o31 && _o31();
      });
    }
  }, {
    key: "setTrackEventListenerByControls",
    value: function setTrackEventListenerByControls(e, t, n, _o32) {
      e.setTrackEventListener(t, function (e, t) {
        for (var _i7 = 0; _i7 < n.length; _i7++) {
          t.data.name == n[_i7] && _o32[_i7] && _o32[_i7]();
        }
      });
    }
  }, {
    key: "setCompleteListenerByControl",
    value: function setCompleteListenerByControl(e, t, n) {
      e.setCompleteListener(function (e) {
        e.animation.name === t && n && n();
      });
    }
  }, {
    key: "setCompleteListenerByControls",
    value: function setCompleteListenerByControls(e, t, n) {
      e.setCompleteListener(function (e) {
        for (var _o45 = 0; _o45 < t.length; _o45++) {
          e.animation.name === t[_o45] && n[_o45] && n[_o45]();
        }
      });
    }
  }, {
    key: "vectorsToDegress",
    value: function vectorsToDegress(e) {
      var t = cc.v2(0, 1);
      var n = e.signAngle(t);
      return cc.misc.radiansToDegrees(n);
    }
  }, {
    key: "DegressTovectors",
    value: function DegressTovectors(e) {
      var t = cc.misc.degreesToRadians(e);
      return cc.v2(0, 1).rotate(-t);
    }
  }, {
    key: "checkWorldBox",
    value: function checkWorldBox(e, t) {
      var n = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
      var _o34 = this.getworldbox(e);
      var i = this.getworldbox(t);
      this._intersecRect.x = this._intersecRect.y = this._intersecRect.width = this._intersecRect.height = 0;
      _o34.intersection(this._intersecRect, i);
      if (this._intersecRect.width <= 0 || this._intersecRect.height <= 0) {
        return false;
      }
      var s = Math.min(_o34.width * _o34.height, i.width * i.height);
      return this._intersecRect.width * this._intersecRect.height / s > n;
    }
  }, {
    key: "getworldbox",
    value: function getworldbox(e) {
      var t = e.width;
      var n = e.height;
      var _o35 = cc.rect(-e.anchorX * t, -e.anchorY * n, t, n);
      e._calculWorldMatrix();
      _o35.transformMat4(_o35, e._worldMatrix);
      return _o35;
    }
  }, {
    key: "getRandomArray",
    value: function getRandomArray(e) {
      var t = [];
      for (var _n12 = 0; _n12 < e; _n12++) {
        t[_n12] = _n12;
      }
      return this.changesjs(t, []);
    }
  }, {
    key: "changesjs",
    value: function changesjs(e, t) {
      if (e.length > 0) {
        var _n13 = this.random(0, e.length - 1);
        t[t.length] = e[_n13];
        e.splice(_n13, 1);
        return this.changesjs(e, t);
      }
      return t;
    }
  }, {
    key: "playSoundCall",
    value: function playSoundCall(e, t, n, _o36, i) {
      if ("" != n) {
        if (_o36 >= e.sayNum.length) {
          e.sayNum[_o36] = 0;
          e.arrCalls[_o36] = [];
        }
        e.stopAudioAll();
        for (var _t17 = 0; _t17 < e.arrCalls.length; _t17++) {
          for (var _n14 = 0; _n14 < e.arrCalls[_t17].length; _n14++) {
            var _o37 = e.arrCalls[_t17][_n14];
            e.arrCalls[_t17].splice(_n14, 1);
            _n14--;
            e.sayNum[_t17]--;
            _o37 && _o37();
            e.sayNum[_t17] <= 0 && (e.shuohuaStrArrs[_t17].node.parent.active = false);
          }
        }
        e.arrCalls[_o36][e.arrCalls[_o36].length] = i;
        e.sayNum[_o36]++;
        e.shuohuaStrArrs[_o36].node.parent.active = true;
        e.shuohuaStrArrs[_o36].string = n;
        this.scheduleOnce(function () {
          e.shuohuaStrArrs[_o36].node.parent.active = true;
        });
        if ($2GameUser.default.getInstance().audio) {
          e.playSound(t).then(function (t) {
            e.changeAudio(t, function () {
              for (var _t18 = 0; _t18 < e.arrCalls[_o36].length; _t18++) {
                if (e.arrCalls[_o36][_t18] == i) {
                  var _n15 = e.arrCalls[_o36][_t18];
                  e.arrCalls[_o36].splice(_t18, 1);
                  _t18--;
                  _n15 && _n15();
                }
              }
              e.sayNum[_o36]--;
              e.sayNum[_o36] <= 0 && (e.shuohuaStrArrs[_o36].node.parent.active = false);
            });
          });
        } else {
          e.scheduleOnce(function () {
            for (var _t19 = 0; _t19 < e.arrCalls[_o36].length; _t19++) {
              if (e.arrCalls[_o36][_t19] == i) {
                var _n16 = e.arrCalls[_o36][_t19];
                e.arrCalls[_o36].splice(_t19, 1);
                _t19--;
                _n16 && _n16();
              }
            }
            e.sayNum[_o36]--;
            e.sayNum[_o36] <= 0 && (e.shuohuaStrArrs[_o36].node.parent.active = false);
          }, 2);
        }
      } else {
        i && i();
      }
    }
  }, {
    key: "bundleLoad",
    value: function bundleLoad(e, t) {
      var n = e.substring(0, 7);
      var _o38 = e.split("/");
      var i = e;
      if ("Res" == n || "Audio" == _o38[0]) {
        $2BundleManager.default.getInstance().resBundle.load(i, function (e, n) {
          if (e) {
            console.log("bundleLoad------", e);
          } else {
            t && t(e, n);
          }
        });
      } else {
        _o38 = (i = e.substring(7)).split("/");
        var _n17 = $2GameConfig.default.getInstance().getConfig($2levelconfig.default).getlevelByName(_o38[0]).levelsBundleName;
        var _r = $2BundleManager.default.getInstance().levelsBundle;
        (_r = "levels" == _n17 ? $2BundleManager.default.getInstance().levelsBundle : $2BundleManager.default.getInstance().levelsBundles[parseInt(_n17)]).load(i, function (e, n) {
          if (e) {
            console.log("bundleLoad------", e);
          } else {
            t && t(e, n);
          }
        });
      }
    }
  }, {
    key: "bundleLoadDir",
    value: function bundleLoadDir(e, t) {
      var n = e.split("/");
      var _o39 = $2GameConfig.default.getInstance().getConfig($2levelconfig.default).getlevelByName(n[0]).levelsBundleName;
      var i = $2BundleManager.default.getInstance().levelsBundle;
      (i = "levels" == _o39 ? $2BundleManager.default.getInstance().levelsBundle : $2BundleManager.default.getInstance().levelsBundles[parseInt(_o39)]).loadDir(e, function (e, n) {
        if (e) {
          console.log("bundleLoad------", e);
        } else {
          t && t(e, n);
        }
      });
    }
  }, {
    key: "changeAudio",
    value: function changeAudio(e, t, n) {
      var _o40 = 2;
      var i = cc.audioEngine.getDuration(t);
      i > 0 && (_o40 = i);
      this.scheduleOnce(function () {
        cc.isValid(e.node) && n && n();
      }, _o40);
    }
  }, {
    key: "screen_fomate",
    value: function screen_fomate(e) {
      this.scheduleOnce(function () {
        var t = e.parent.width > 1e3 ? 1e3 : e.parent.width;
        var n = e.width;
        var _o41 = e.parent.height > 1e3 ? 1e3 : e.parent.height;
        var i = e.height;
        var s = n / i;
        var a = t / _o41;
        e.scale = s > a ? t / n : _o41 / i;
      });
    }
  }, {
    key: "loadBundles",
    value: function loadBundles(e, t) {
      console.log("loadlevelsBundle:");
      var n = new Date().getTime();
      cc.assetManager.loadBundle(e, function (_o42, i) {
        if (_o42) {
          console.log("err:", _o42);
        } else {
          var _o43 = new Date().getTime() - n;
          console.log("time:----------------------------:", _o43);
          if ("levels" == e) {
            $2BundleManager.default.getInstance().levelsBundle = i;
          } else {
            var _t20 = parseInt(e);
            $2BundleManager.default.getInstance().levelsBundles[_t20] = i;
          }
          t && t(i);
        }
      });
    }
  }], [{
    key: "getInstance",
    value: function getInstance() {
      null == this.instance && (this.instance = new _o28());
      return this.instance;
    }
  }, {
    key: "linkMouse",
    value: function linkMouse() {
      var e = cc.sys.isMobile;
      var t = ("mouse" in cc.sys.capabilities);
      var n = ("touches" in cc.sys.capabilities);
      if (e && t && n) {
        var _e26 = cc.internal.inputManager;
        var _t21 = cc.internal.eventManager;
        var _n18 = _e26;
        var _o44 = cc.game.canvas;
        var _i8 = _e26._canvasBoundingRect;
        var _s3 = [["mousedown", 1, function (e, t, i, s) {
          _n18._mousePressed = true;
          _n18.handleTouchesBegin([_n18.getTouchByXY(i.x, i.y, s)]);
          _o44.focus();
        }], ["mouseup", 2, function (e, t, o, i) {
          _n18._mousePressed = false;
          _n18.handleTouchesEnd([_n18.getTouchByXY(o.x, o.y, i)]);
        }], ["mousemove", 3, function (e, t, o, i) {
          _n18.handleTouchesMove([_n18.getTouchByXY(o.x, o.y, i)]);
          _n18._mousePressed || t.setButton(null);
        }], ["mousewheel", 4, function (e, t) {
          t.setScrollData(0, e.wheelDelta);
        }], ["DOMMouseScroll", 5, function (e, t) {
          t.setScrollData(0, -120 * e.detail);
        }]];
        var _loop2 = function _loop2() {
          var e = _s3[_a15];
          if (e) {
            var _s4 = e[0];
            var _a16 = e[1];
            var _r2 = e[2];
            _o44.addEventListener(_s4, function (e) {
              var o = _n18.getPointByEvent(e, _i8);
              var s = _n18.getMouseEvent(o, _i8, _a16);
              s.setButton(e.button);
              _r2(e, s, o, _i8);
              _t21.dispatchEvent(s);
              e.stopPropagation();
              e.preventDefault();
            }, false);
          }
        };
        for (var _a15 = 0; _a15 < _s3.length; ++_a15) {
          _loop2();
        }
      }
    }
  }]);
}(cc.Component);
def_Globe.instance = null;
def_Globe = _o28 = cc__decorate([ccp_ccclass], def_Globe);
exports.default = def_Globe;